//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.example.hfiveandaplication.utils;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.UUID;

public class DeviceUtils {
    public DeviceUtils() {
    }

    public static String getVersionNameAndVersionCode(Context context) {
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
            return info.versionName + "." + info.versionCode;
        } catch (Exception var3) {
            DebugLog.e("getVersionNameAndVersionCode  Exception::", var3);
            return "";
        }
    }

    public static String getVersionName(Context context) {
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
            return info.versionName;
        } catch (Exception var3) {
            DebugLog.e("getVersionNameAndVersionCode  Exception::", var3);
            return "";
        }
    }

    public static String getImei(Context context) {
        try {
            @SuppressLint("WrongConstant") TelephonyManager tm = (TelephonyManager) context.getSystemService("phone");
            if (tm != null) {
                String deviceId = tm.getDeviceId();
                if (!TextUtils.isEmpty(deviceId)) {
                    return deviceId;
                }
            }
        } catch (Exception var3) {
            DebugLog.d(var3.getMessage());
        }

        return "";
    }

    public static String getMac(Context context) {
        String mac = null;
        @SuppressLint("WrongConstant") WifiManager wifi = (WifiManager) context.getSystemService("wifi");
        if (wifi != null) {
            WifiInfo info = wifi.getConnectionInfo();
            if (info != null) {
                mac = info.getMacAddress();
                return mac;
            }
        }

        return UUID.randomUUID().toString();
    }

    public static String getMac() {
        String str = "";
        String macSerial = "";

        try {
            Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address ");
            InputStreamReader ir = new InputStreamReader(pp.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);

            while (null != str) {
                str = input.readLine();
                if (str != null) {
                    macSerial = str.trim();
                    break;
                }
            }
        } catch (Exception var6) {
            var6.printStackTrace();
        }

        if (macSerial == null || "".equals(macSerial)) {
            try {
                return FileUtils.loadFileAsString("/sys/class/net/eth0/address").toUpperCase().substring(0, 17);
            } catch (Exception var5) {
                var5.printStackTrace();
            }
        }

        return macSerial;
    }

    public static String getDeviceIdentifier(Context context) {
        String imei = getImei(context);
        return TextUtils.isEmpty(imei) ? getMac(context) : getImei(context);
    }

    public static String getAndroidId(Context context) {
        String androidId = Secure.getString(context.getContentResolver(), "android_id");
        return androidId != null ? androidId : UUID.randomUUID().toString();
    }

    public static String getCPUSerial() {
        String str = "";
        String strCPU = "";
        String cpuAddress = "0000000000000000";

        try {
            Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo");
            InputStreamReader ir = new InputStreamReader(pp.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);

            for (int i = 1; i < 100; ++i) {
                str = input.readLine();
                if (str == null) {
                    break;
                }

                if (str.indexOf("Serial") > -1) {
                    strCPU = str.substring(str.indexOf(":") + 1, str.length());
                    cpuAddress = strCPU.trim();
                    break;
                }
            }
        } catch (IOException var7) {
            var7.printStackTrace();
        }

        return cpuAddress;
    }

    public static String getModel() {
        return Build.MODEL;
    }

    public static String getBrand() {
        return Build.BRAND;
    }

    public static String getOSversion() {
        return VERSION.RELEASE;
    }

    public static String getSdkVersion() {
        return VERSION.SDK;
    }

    public static void dial(String number, Context context) {
        Class<TelephonyManager> c = TelephonyManager.class;
        Method getITelephonyMethod = null;

        try {
            getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null);
            getITelephonyMethod.setAccessible(true);
            @SuppressLint("WrongConstant") TelephonyManager tManager = (TelephonyManager) context.getSystemService("phone");
            Object iTelephony = getITelephonyMethod.invoke(tManager, (Object[]) null);
            Method dial = iTelephony.getClass().getDeclaredMethod("dial", String.class);
            dial.invoke(iTelephony, number);
        } catch (SecurityException var7) {
            DebugLog.i(var7.getMessage());
        } catch (NoSuchMethodException var8) {
            DebugLog.i(var8.getMessage());
        } catch (IllegalArgumentException var9) {
            DebugLog.i(var9.getMessage());
        } catch (IllegalAccessException var10) {
            DebugLog.i(var10.getMessage());
        } catch (InvocationTargetException var11) {
            DebugLog.i(var11.getMessage());
        }

    }

    public static String getSystemAvaialbeMemorySize(Context context) {
        MemoryInfo memoryInfo = new MemoryInfo();
        @SuppressLint("WrongConstant") ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
        activityManager.getMemoryInfo(memoryInfo);
        long memSize = memoryInfo.availMem;
        return FileSize.convertSizeToString(memSize);
    }

    public static long getSystemAvaialbeMemory(Context context) {
        MemoryInfo memoryInfo = new MemoryInfo();
        @SuppressLint("WrongConstant") ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
        activityManager.getMemoryInfo(memoryInfo);
        return memoryInfo.availMem;
    }

    public static boolean hasFroyo() {
        return VERSION.SDK_INT >= 8;
    }

    public static boolean hasGingerbread() {
        return VERSION.SDK_INT >= 9;
    }

    public static boolean hasHoneycomb() {
        return VERSION.SDK_INT >= 11;
    }

    public static boolean hasHoneycombMR1() {
        return VERSION.SDK_INT >= 12;
    }

    public static boolean hasIceCreamSandwich() {
        return VERSION.SDK_INT >= 14;
    }

    public static boolean hasIceCreamSandwichMR1() {
        return VERSION.SDK_INT >= 15;
    }

    public static boolean hasJellyBean() {
        return VERSION.SDK_INT >= 16;
    }

    public static boolean hasJellyBeanMR1() {
        return VERSION.SDK_INT >= 17;
    }

    public static boolean hasKITKAT() {
        return VERSION.SDK_INT >= 19;
    }

    public static boolean hasKitkatWatch() {
        return VERSION.SDK_INT >= 20;
    }

    public static boolean hasLollipop() {
        return VERSION.SDK_INT >= 21;
    }

    public static String getPlatform() {
        return "android";
    }

    public static String getDeviceInfo(Context context) {
        StringBuilder buffer = new StringBuilder();
        buffer.append("device brand:").append(getBrand());
        buffer.append(", device os version:").append(getOSversion());
        buffer.append(", device os modle:").append(getModel());
        buffer.append(", imei:").append(getImei(context));
        buffer.append(", app version:").append(getVersionNameAndVersionCode(context));
        return buffer.toString();
    }

    public static String getImsi(Context context) {
        @SuppressLint("WrongConstant") TelephonyManager mTelephonyMgr = (TelephonyManager) context.getSystemService("phone");
        return mTelephonyMgr.getSubscriberId();
    }

    public static String getSDKVersion() {
        return VERSION.SDK_INT + "";
    }

    public static boolean isDieviceIdUnvalid(Context context) {
        return TextUtils.isEmpty(getAndroidId(context)) || getAndroidId(context).equals("0");
    }

    public static String getDefaultUserAgent() {
        return System.getProperty("http.agent");
    }

    public static void getGpuInfo(){

    }

}
